/**
 * 添加机场
 * @author willimJM
 * date 2018/05/17
 */

"use strict";


define(["app","config/pathConfig","layer"],function(app,pathConfig,layer) {

    app.registerController("ctrl.airport.addAirport",function ($scope,$http) {

        $scope.airport = {
            state: "1",
            numRunways: "1"
        };

        var submit = function (airport) {
            return new Promise(function (success, error) {
                $http.post(pathConfig.backstagePath.getPath() + "/airport", airport)
                    .then(function successCallback(response) {
                        success(response);
                    })
            })
        };

        $scope.save = function () {
            layer.confirm('确定要保存当前的机场信息吗？', {
                icon: 3,
                title: '保存提示',
                btn: ['确定', '取消']
            }, function () {
                var loding = layer.msg("正在保存，请稍后...", {icon: 16,shade: 0.01});
                submit($scope.airport).then(function success(response) {
                    layer.close(loding);
                    if(response.data.status === 200) {
                        layer.msg("保存成功！", {icon: 1,time:1500});
                        return;
                    }
                    if(response.data.status === 200) {
                        layer.msg("保存失败！", {icon: 2,time:1500});
                    }
                })
            });
        }





    });
});